//初始化数据
var app = new getApp()
var api = require('../utils/api.js')

function tabbarinit() {
  return [{
      "current": 0,
      "pagePath": "/pages/index/index",
      "iconPath": "/imgs/2.png",
      "selectedIconPath": "/imgs/a2.png",
      "text": "选材"
    },
    {
      "current": 0,
      "pagePath": "/pages/custom/index",
      "iconPath": "/imgs/6.png",
      "selectedIconPath": "/imgs/a6.png",
      "text": "空间"

    },
    {
      "current": 0,
      "pagePath": "/pages/center/index",
      "iconPath": "/imgs/5.png",
      "selectedIconPath": "/imgs/a5.png",
      "text": "我的"
    }
  ]

}

/**
 * tabbar主入口
 * @param  {String} bindName 
 * @param  {[type]} id       [表示第几个tabbar，以0开始]
 * @param  {[type]} target   [当前对象]
 */
function tabbarmain(bindName = "tabdata", id, target) {
  var that = target;
  var bindData = {};
  var otabbar = tabbarinit();
  otabbar[id]['iconPath'] = otabbar[id]['selectedIconPath'] //换当前的icon
  otabbar[id]['current'] = 1;
  bindData[bindName] = otabbar
  //data new通知
  // api.get('read').then(res=>{
  //   this.setData({
  //     ct:res.data
  //   })
  // })
  // api.get('read').then(res => {
  //   otabbar[4]['hasData'] = res.data
  //   that.setData({
  //     bindData
  //   })
  // }).catch((err) => {
  //   that.setData({
  //     bindData
  //   })
  // })
  // var hd = app.globalData.hasData
  // if (hd) {
  //   otabbar[4]['hasData'] = hd
  // }
  that.setData({
    bindData
  });
}


module.exports = {
  tabbar: tabbarmain
}